﻿/*************************************************************************************
 * 文 件 名:   UI_RoamCamCtrl
 * 
 * 描    述:   RoamingCam的UI测试脚本
 * 
 * 版    本：  V1.0
 * 创 建 者：  谭潇杰、京产肠饭
 * 创建时间：  2022/1/28
 * 链   接：  https://gitee.com/JingChanChangFan/hk_-unity-tools
*************************************************************************************/

using UnityEngine;
using UnityEngine.UI;

public class UI_RoamCamTestCtrl : MonoBehaviour
{
    [Header("底部三个开关：")]

    [SerializeField] Toggle roam_Toggle;
    [SerializeField] Toggle birdView_Toggle;
    [SerializeField] Toggle threeD_Toggle;

    void Start()
    {
        roam_Toggle.onValueChanged.AddListener(OnClickRoamToggle);
        birdView_Toggle.onValueChanged.AddListener(OnClickBirdViewToggle);
        threeD_Toggle.onValueChanged.AddListener(OnClickThreeToggle);

        HK_Player.Ins.ViewModeChangeEvent += OnViewModeChangeEvent;
        HK_Player.Ins.IsCanRotCamEvent += OnIsCanRotCamEvent;
    }

    void OnDestroy()
    {
        HK_Player.Ins.ViewModeChangeEvent -= OnViewModeChangeEvent;
        HK_Player.Ins.IsCanRotCamEvent -= OnIsCanRotCamEvent;
    }

    //点击漫游
    void OnClickRoamToggle(bool isOn)
    {
        if (!isOn || !HK_Player.Ins.IsCanRotCam)
            return;

        HK_Player.Ins.ChangeToRoamMode(HK_Player.Ins.lastPoint);
    }

    //点击鸟瞰
    void OnClickBirdViewToggle(bool isOn)
    {
        if (!isOn || !HK_Player.Ins.IsCanRotCam)
            return;

        HK_Player.Ins.ChangeToBirdViewMode();
    }

    //点击三维Toggle
    void OnClickThreeToggle(bool isOn)
    {
        if (!isOn || !HK_Player.Ins.IsCanRotCam)
            return;

        HK_Player.Ins.ChangeToThreeDMode();
    }

    //等待时间结束设置开关
    void OnViewModeChangeEvent(ViewMode viewMode)
    {
        switch (viewMode)
        {
            case ViewMode.BirdView:
                birdView_Toggle.isOn = true;
                break;
            case ViewMode.ThreeD:
                threeD_Toggle.isOn = true;
                break;
            case ViewMode.Roam:
                roam_Toggle.isOn = true;
                break;
        }
    }

    void OnIsCanRotCamEvent(bool isCanRotCam)
    {
        roam_Toggle.interactable = isCanRotCam;
        birdView_Toggle.interactable = isCanRotCam;
        threeD_Toggle.interactable = isCanRotCam;
    }
}
